<?php

require ROOT_PATH . 'jpush-api-php-client/autoload.php';

use  JPush\Client as Jpush;

function sendJpush($pushInfo)
{
    $client = new JPush('5c6935ddb7e09082e0fb8e33', 'c27d1d71447080cdf76bbd45');
    $pusher = $client->push();
    $pusher->setPlatform(['android', 'ios']);
    $pusher->addAllAudience();
//        $pusher->addRegistrationId(['190e35f7e0f75a1959a','101d855909f662eb7f4','1114a89792194ffb9ea','160a3797c8b44a0304e','13065ffa4ebfb07afdb','100d855909f4b8080c0','1a1018970a10257ca87']);
    $pusher->androidNotification(
        $pushInfo['content'],
        [
            'title' => $pushInfo['title'],
            'builder_id' => 0,
            'extras' => $pushInfo
        ]
    );

    $pusher->iosNotification(
        [
            "title" => $pushInfo['title'],
            "subtitle" => !empty($pushInfo['subtitle']) ? $pushInfo['subtitle'] : '',
            "body" => $pushInfo['content'],
        ],
        [
            'content-available' => true,
            'category' => 'jiguang',
            'extras' => $pushInfo
        ]
    );
//       $pusher->message('Hello JPush', [
//           'title' => 'Hello',
//           'content_type' => 'text',
//           'extras' => [
//               'key' => 'value',
//               'jiguang'=>1
//           ]
//       ]);
    $pusher->options(['apns_production' => true]);
    try {
        return $pusher->send();
    } catch (\JPush\Exceptions\JPushException $e) {
        // try something else here
        return $e;
    }
}


function getZhiboStatus($status)
{
    switch ($status) {
        case  0:
            return '尚未开始';
        case 1:
            return '直播中';
        case 2:
            return '信号中断';
        default:
            break;
    }
}

function getOpenAdLogType($type)
{
    switch ($type) {
        case 7:
            $typeName = "新安装app";
            break;
        case 6:
            $typeName = "新启动app";
            break;
        case 5:
            $typeName = "热更新";
            break;
        case 4:
            $typeName = "Banner广告";
            break;
        case 3:
            $typeName = "广告-直播详情-小屏视频";
            break;
        case 2:
            $typeName = "广告-影视详情-全屏视频";
            break;
        case 1:
            $typeName = "广告-开屏视频";
            break;
        case -1:
            $typeName = "体育直播";
            break;
        case -2:
            $typeName = "影视";
            break;
        default:
            $typeName = "";
            break;
    }

    return $typeName;
}

function getOpenAdVideoInfo($openAdLog)
{
    switch ($openAdLog['adtype']) {
        case -1:
            $text = '[' . $openAdLog['zhibo_id'] . '] ' . $openAdLog['zhibo_name'];
            break;
        case -2:
            $text = '[' . $openAdLog['vod_id'] . '] ' . $openAdLog['vod_name'];
            if (!empty($openAdLog['yuan'])) {
                $text .= ' [播放源 ' . $openAdLog['yuan'] . "] ";
            }
            if (!empty($openAdLog['xuanji'])) {
                $text .= " ".$openAdLog['xuanji'];
            }
            if($openAdLog['shichang']>0){
                $text .= " 播放进度 ".($openAdLog['shichang'] * 100)."%";
            }
            $text = (!empty($openAdLog) ? ($openAdLog['memo'] . " ") : " ") . $text;
            break;
        case 2:
        case 3:
        case 4:
        case 1:
            $text = $openAdLog['memo'];
            if($openAdLog['vod_id']>0){
                $text = '[' . $openAdLog['vod_id'] . '] ' . $openAdLog['vod_name'] ." ".$text;
            }

            if($openAdLog['zhibo_id']>0){
                $text = '[' . $openAdLog['zhibo_id'] . '] ' . $openAdLog['zhibo_name'] ." ".$text;

            }
            break;
        default:
            break;
    }

    return $text;
}